//
//  MXFoodCountCell.m
//  HNBaseProject
//
//  Created by xujie on 2024/6/5.
//

#import "MXFoodCountCell.h"

@implementation MXFoodCountCell

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self createUIWithFrame:frame];
    }
    return self;
}

- (void)createUIWithFrame:(CGRect)frame {
    self.backgroundColor = [UIColor whiteColor];
    
    CGFloat width = (kScreenW -42) / 5.0 -6;
    self.bgView = [[UIView alloc] init];
    self.bgView.layer.cornerRadius = width/2.0;
    self.bgView.layer.masksToBounds = YES;
    self.bgView.hidden = YES;
    self.bgView.backgroundColor = [UIColor colorWithHexString:@"#46AEF7"];
    
    
    [self.contentView addSubview:self.bgView];
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.width.mas_equalTo(width);
        make.center.mas_equalTo(self.contentView);
    }];
    
    self.numLab = [[UILabel alloc] init];
    self.numLab.textColor = [UIColor dc_colorWithHexString:@"#000000" alpha:0.4];
    [self.contentView addSubview:self.numLab];
    self.numLab.text = @"1";
    [self.numLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.contentView);
        make.top.offset(23);
    }];
    
    self.unitLab = [[UILabel alloc] init];
    self.unitLab.textColor = [UIColor dc_colorWithHexString:@"#000000" alpha:0.4];
    [self.contentView addSubview:self.unitLab];
    self.unitLab.text = @"份";
    [self.unitLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.contentView);
        make.bottom.offset(-12);
    }];
    //23
}

- (void)reloadCellWithSelect:(BOOL)select count:(NSString *)count {
    self.numLab.text = count;
    if (select) {
        self.bgView.hidden = NO;
        self.numLab.textColor = [UIColor whiteColor];
        self.unitLab.textColor = [UIColor whiteColor];
        self.numLab.font = PFRFontMedium(36);
        self.unitLab.font = PFRFont(14);
        
        [self.numLab mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self.contentView);
            make.top.offset(0);
        }];
        
        [self.unitLab mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self.contentView);
            make.bottom.offset(-11);
        }];
    } else {
        self.bgView.hidden = YES;
        self.numLab.textColor = [UIColor dc_colorWithHexString:@"#000000" alpha:0.4];
        self.unitLab.textColor = [UIColor dc_colorWithHexString:@"#000000" alpha:0.4];
        self.numLab.font = PFRFontMedium(18);
        self.unitLab.font = PFRFont(10);
        [self.numLab mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self.contentView);
            make.top.offset(23);
        }];
        
        [self.unitLab mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self.contentView);
            make.bottom.offset(-12);
        }];
    }
}


@end
